import {createRouter, createWebHashHistory} from "vue-router";

const routes = [
    {
        path: '/',
        redirect: '/login'
    },

    {
        path: '/:catchALL(.*)',
        name: 'Error',
        component: () => import('../views/Error')
    },

    {
        path: '/detail',
        name: 'Detail',
        component: () => import('../views/detail/Detail')
    },


    {
        path: '/home',
        name: 'Home',
        component: () => import('../views/home/Home'),
        meta:{
            title:'网上商城'
        }
    },

    {
        path: '/profile',
        name: 'Profile',
        component: () => import('../views/profile/Profile'),
        meta:{
            title:'个人中心'
        }
    },


    {
        path: '/category',
        name: 'Category',
        component: () => import('../views/category/Category'),
        meta:{
            title:'商品分类'
        }
    },

    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/login/Login')
    },

    {
        path: '/shopCart',
        name: 'ShopCart',
        component: () => import('../views/shopCart/shopCart'),
        meta:{
            title:'购物车'
        }
    }
]

const router = createRouter({
    history: createWebHashHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to,from,next) =>{
    next()
    document.title = to.meta.title
})

export default router
